/*
The MIT License (MIT)

Copyright (c) 2015 Stanislav Podgorskiy (Pidhorskyi)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>


class SimpleTextImplDetails;

/*	Public API. */

class SimpleText
{
public:
	enum FontSize
	{
		SIZE_16 = 1,
		SIZE_32,
		SIZE_48,
		SIZE_64,
		SIZE_96,
		SIZE_112,
		SIZE_128,
		SIZE_160,
		SIZE_176,
		SIZE_192,
	};

	enum Alignment
	{
		LEFT,
		CENTER,
		RIGHT
	};

	enum ForegroundBackground
	{
		TEXT_COLOR,
		BACKGROUND_COLOR
	};

	enum Color
	{
		BLACK,
		RED,
		GREEN,
		YELLOW,
		BLUE,
		MAGENTA,
		CYAN,
		WHITE,
		COLOR_COUNT
	};

	enum NormalBold
	{
		NORMAL,
		BOLD
	};

	SimpleText();

	~SimpleText();

	void Label(const char* text, int posX, int posY, Alignment a=LEFT);

	void SetColor(ForegroundBackground type, Color color, NormalBold bold = NORMAL);

	void SetColor(ForegroundBackground type, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
	void SetColorf(ForegroundBackground type, float r, float g, float b, float a = 1.0f);

	void SetTextSize(FontSize size);

	void EnableBlending(bool enabled);

	void ResetFont();

	void Render();

	// API for symbol by symbol rendering
	void SubmitSymbol(char s, int x, int y);
private:
	friend class SimpleTextImplDetails;
	SimpleTextImplDetails* m_impl;
};


/*	Private implementation details. */


#ifndef SIMPLE_TEXT_PRINT_ERROR
#define SIMPLE_TEXT_PRINT_ERROR(...) printf(__VA_ARGS__)
#endif

class SimpleTextImplDetails
{
	enum FontProperties
	{
		TEXTURE_SIZE_X = 256,
		TEXTURE_SIZE_Y = 256,
		SYMBOL_COUNT = 256,
		SYMBOL_HEIGHT = 16,
		SYMBOL_WIDTH = 8,
	};
	
	enum Stage
	{
		COMPILE,
		LINK,
	};

	enum Attributes
	{
		AttributePosition = 0,
		AttributeTextureCoord = 1,
		AttributeColorF = 2,
		AttributeColorB = 3,
	};

	enum
	{
		min_size = 0x1000,
		vertex_size = (sizeof(int16_t) * 2 + sizeof(int16_t) * 2 + sizeof(uint8_t) * 8),
	};

	class ANSI_EscapeCodeDecoder
	{
	public:
		class IEscapeCodeExecuter
		{
		public:
			virtual ~IEscapeCodeExecuter(){};
			virtual void SetColor(SimpleText::ForegroundBackground type, SimpleText::NormalBold bold, SimpleText::Color color) = 0;
			virtual void GetColor(SimpleText::ForegroundBackground type, SimpleText::NormalBold& bold, SimpleText::Color& color) = 0;
		};
		bool DecodeEscapeCode(const char*& iterator, const char* end, char& symbol);
		void SetExecutor(IEscapeCodeExecuter* object);
		IEscapeCodeExecuter* GetExecutor();
	private:
		bool AcceptSymbol(char symbol, const char*& iterator, const char* end);
		bool AcceptDigit(const char*& iterator, const char* end, int& digit);
		bool AcceptNumber(const char*& iterator, const char* end, int& number);
		void DecodeCommand(int cmd);
		void Apply();
		void Reset();
		IEscapeCodeExecuter* m_callBack;

		bool m_setBold;
		bool m_setNormal;
		bool m_setBackgroundColor;
		bool m_setTextColor;

		SimpleText::Color m_textColor;
		SimpleText::Color m_backgroundColor;
	};

	class EscapeCodeExecuter :public ANSI_EscapeCodeDecoder::IEscapeCodeExecuter
	{
	public:
		EscapeCodeExecuter(SimpleTextImplDetails* owner);
		virtual void SetColor(SimpleText::ForegroundBackground type, SimpleText::NormalBold bold, SimpleText::Color color);
		virtual void GetColor(SimpleText::ForegroundBackground type, SimpleText::NormalBold& bold, SimpleText::Color& color);
		SimpleTextImplDetails* m_owner;
	};

public:
	template<typename T>
	inline static T clamp(T x, T low, T high)
	{
		return x < low ? low : (x > high ? high : x);
	}

	SimpleTextImplDetails();
	~SimpleTextImplDetails();
	void CreateFontTexture();
	void CreateShaderProgram();
	void CreateVBO();
	void Free();
	void BindAttributes();
	void BindUniforms();
	unsigned char* GenerateFontBitmap();
	void SetColor(SimpleText::ForegroundBackground type, SimpleText::Color color, SimpleText::NormalBold bold);
	void GetColor(SimpleText::ForegroundBackground type, SimpleText::Color &color, SimpleText::NormalBold &bold);
	void ResetAnsiColor();
	void DecodeColor(SimpleText::Color color, SimpleText::NormalBold bold, unsigned char& r, unsigned char& g, unsigned char& b);
	void EnableBlending(bool enabled);
	bool Succeeded(GLuint object, Stage stage);
	void SetColor(SimpleText::ForegroundBackground type, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
	void SetTextSize(SimpleText::FontSize size);
	void Label(const char* text, int posX, int posY, SimpleText::Alignment a);
	void SubmitSymbol(char symbol, float posX, float posY, int shift);

	void Render();
private:
	void StartDraw();
	void EndDraw();
	void ResizeVertexBuffer(size_t newSize);

	GLuint m_vbo;
	GLuint m_ibo;

	GLuint m_texture;
	GLuint m_vertexShader;
	GLuint m_fragmentShader;
	GLuint m_shaderprogram;

	GLint u_texture;
	GLint u_viewport;

	uint8_t* m_vertex_buffer;
	uint16_t* m_index_buffer;
	size_t m_vertex_buffer_size;
	size_t m_vertex_buffer_reserved;
	size_t m_vertex_buffer_offset;
	size_t m_vertex_count;

	SimpleText::FontSize m_fontsize;
	int m_sizeX;
	int m_sizeY;
	GLint m_viewport[4];

	uint8_t m_textColor[4];
	uint8_t m_backColor[4];

	GLint m_backUpSfactorRGB;
	GLint m_backUpDfactorRGB;
	GLint m_backUpSfactorAlpha;
	GLint m_backUpDfactorAlpha;

	bool m_blendingEnabled;
	GLboolean m_backUpBlendingState;

	ANSI_EscapeCodeDecoder m_ansiDecoder;

	SimpleText::Color m_ansiTextColor;
	SimpleText::Color m_ansiBackgroundColor;
	SimpleText::NormalBold m_ansiBold;
};



inline SimpleText::SimpleText()
{
	m_impl = new SimpleTextImplDetails;
	m_impl->CreateFontTexture();
	m_impl->CreateShaderProgram();
	m_impl->CreateVBO();
	m_impl->BindAttributes();
	m_impl->BindUniforms();
	ResetFont();
}

inline SimpleText::~SimpleText()
{
	m_impl->Free();
	delete m_impl;
}

inline void SimpleText::ResetFont()
{
	SetTextSize(SIZE_16);
	SetColor(SimpleText::TEXT_COLOR, WHITE, NORMAL);
	SetColor(SimpleText::BACKGROUND_COLOR, BLACK, NORMAL);
	EnableBlending(false);
}

inline void SimpleText::EnableBlending(bool enabled)
{
	m_impl->EnableBlending(enabled);
}

inline void SimpleText::Label(const char* text, int posX, int posY, SimpleText::Alignment a)
{
	m_impl->Label(text, posX, posY, a);
}

inline void SimpleText::Render()
{
	m_impl->Render();
}

inline void SimpleText::SubmitSymbol(char s, int x, int y)
{
	m_impl->SubmitSymbol(s, static_cast<float>(x), static_cast<float>(y), 0);
}

inline void SimpleText::SetColor(ForegroundBackground type, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
	m_impl->SetColor(type, r, g, b, a);
}

void SimpleText::SetColorf(ForegroundBackground type, float r, float g, float b, float a)
{
	uint8_t _r = SimpleTextImplDetails::clamp(static_cast<int>(r * 255.0f), 0, 255);
	uint8_t _g = SimpleTextImplDetails::clamp(static_cast<int>(g * 255.0f), 0, 255);
	uint8_t _b = SimpleTextImplDetails::clamp(static_cast<int>(b * 255.0f), 0, 255);
	uint8_t _a = SimpleTextImplDetails::clamp(static_cast<int>(a * 255.0f), 0, 255);
	m_impl->SetColor(type, _r, _g, _b, _a);
}

inline void SimpleText::SetColor(ForegroundBackground type, Color color, NormalBold bold)
{
	m_impl->SetColor(type, color, bold);
}

inline void SimpleText::SetTextSize(FontSize size)
{
	m_impl->SetTextSize(size);
}

inline SimpleTextImplDetails::SimpleTextImplDetails() :m_vertexShader(0), m_fragmentShader(0), m_shaderprogram(0), m_vertex_buffer(
		nullptr), m_vertex_buffer_size(0), m_vertex_buffer_reserved(0), m_vertex_buffer_offset(0), m_vertex_count(0), m_viewport{0}
{
	m_ansiDecoder.SetExecutor(new EscapeCodeExecuter(this));
	m_vertex_buffer = nullptr;
	m_index_buffer = nullptr;
	m_vertex_buffer_reserved = 0;
	ResizeVertexBuffer(min_size);
}

inline SimpleTextImplDetails::~SimpleTextImplDetails()
{
	delete m_ansiDecoder.GetExecutor();
}

inline SimpleTextImplDetails::EscapeCodeExecuter::EscapeCodeExecuter(SimpleTextImplDetails* owner) :m_owner(owner)
{
}

inline void SimpleTextImplDetails::EscapeCodeExecuter::SetColor(SimpleText::ForegroundBackground type, SimpleText::NormalBold bold, SimpleText::Color color)
{
	m_owner->SetColor(type, color, bold);
}

inline void SimpleTextImplDetails::EscapeCodeExecuter::GetColor(SimpleText::ForegroundBackground type, SimpleText::NormalBold& bold, SimpleText::Color& color)
{
	m_owner->GetColor(type, color, bold);
}

inline void SimpleTextImplDetails::ANSI_EscapeCodeDecoder::SetExecutor(IEscapeCodeExecuter* object)
{
	m_callBack = object;
}

inline SimpleTextImplDetails::ANSI_EscapeCodeDecoder::IEscapeCodeExecuter* SimpleTextImplDetails::ANSI_EscapeCodeDecoder::GetExecutor()
{
	return m_callBack;
}

inline bool SimpleTextImplDetails::ANSI_EscapeCodeDecoder::AcceptSymbol(char symbol, const char*& iterator, const char* end)
{
	if (iterator == end)
	{
		return false;
	}
	if (symbol == *iterator)
	{
		++iterator;
		return true;
	}
	return false;
}

inline bool SimpleTextImplDetails::ANSI_EscapeCodeDecoder::AcceptDigit(const char*& iterator, const char* end, int& digit)
{
	if (iterator == end)
	{
		return false;
	}
	if (*iterator >= '0' && *iterator <= '9')
	{
		digit = static_cast<int>(*iterator - '0');
		++iterator;
		return true;
	}
	return false;
}

inline bool SimpleTextImplDetails::ANSI_EscapeCodeDecoder::AcceptNumber(const char*& iterator, const char* end, int& number)
{
	int digit = 0;
	if (AcceptDigit(iterator, end, digit))
	{
		number = digit;
		while (AcceptDigit(iterator, end, digit))
		{
			number = number * 10 + digit;
		}
		return true;
	}
	else
	{
		return false;
	}
}

inline void SimpleTextImplDetails::ANSI_EscapeCodeDecoder::DecodeCommand(int cmd)
{
	if (cmd == 0)
	{
		m_setNormal = true;
		m_setBackgroundColor = true;
		m_setTextColor = true;
		m_textColor = SimpleText::WHITE;
		m_backgroundColor = SimpleText::BLACK;
	}
	else if (cmd == 1)
	{
		m_setBold = true;
	}
	else if (cmd == 22)
	{
		m_setNormal = true;
	}
	else if ((cmd / 10 == 3) || (cmd / 10 == 4))
	{
		bool* setColor = cmd / 10 == 3 ? &m_setTextColor : &m_setBackgroundColor;
		SimpleText::Color* colorToSet = cmd / 10 == 3 ? &m_textColor : &m_backgroundColor;
		int color = cmd % 10;
		if (color < 8)
		{
			*setColor = true;
			*colorToSet = static_cast<SimpleText::Color>(color);
		}
		else if (color == 9)
		{
			*setColor = true;
			*colorToSet = cmd / 10 == 3 ? SimpleText::WHITE : SimpleText::BLACK;
		}
	}
}

inline void SimpleTextImplDetails::ANSI_EscapeCodeDecoder::Apply()
{
	if (m_setTextColor)
	{
		if (!m_setNormal && !m_setBold)
		{
			SimpleText::NormalBold previousBold;
			SimpleText::Color previousColor;
			m_callBack->GetColor(SimpleText::TEXT_COLOR, previousBold, previousColor);
			m_callBack->SetColor(SimpleText::TEXT_COLOR, previousBold, m_textColor);
		}
		else
		{
			SimpleText::NormalBold bold = m_setNormal ? SimpleText::NORMAL : SimpleText::BOLD;
			m_callBack->SetColor(SimpleText::TEXT_COLOR, bold, m_textColor);
		}
	}
	else if (m_setNormal || m_setBold)
	{
		SimpleText::NormalBold previousBold;
		SimpleText::Color previousColor;
		m_callBack->GetColor(SimpleText::TEXT_COLOR, previousBold, previousColor);
		SimpleText::NormalBold bold = m_setNormal ? SimpleText::NORMAL : SimpleText::BOLD;
		m_callBack->SetColor(SimpleText::TEXT_COLOR, bold, previousColor);
	}
	if (m_setBackgroundColor)
	{
		m_callBack->SetColor(SimpleText::BACKGROUND_COLOR, SimpleText::NORMAL, m_backgroundColor);
	}
}

inline void SimpleTextImplDetails::ANSI_EscapeCodeDecoder::Reset()
{
	m_setBackgroundColor = false;
	m_setTextColor = false;
	m_setBold = false;
	m_setNormal = false;
}

inline bool SimpleTextImplDetails::ANSI_EscapeCodeDecoder::DecodeEscapeCode(const char*& iterator, const char* end, char& symbol)
{
	if (AcceptSymbol('\033', iterator, end))
	{
		Reset();
		const char* backUpIterator = iterator;
		if (AcceptSymbol('[', iterator, end))
		{
			int number;
			if (AcceptNumber(iterator, end, number))
			{
				DecodeCommand(number);
				while (!AcceptSymbol('m', iterator, end) && (iterator != end))
				{
					if (AcceptSymbol(';', iterator, end))
					{
						if (AcceptNumber(iterator, end, number))
						{
							DecodeCommand(number);
						}
						else
						{
							iterator = backUpIterator;
							return false;
						}
					}
					else
					{
						iterator = backUpIterator;
						return false;
					}
				}
				if (iterator != end)
				{
					Apply();
					return true;
				}
			}
			else
			{
				iterator = backUpIterator;
				return false;
			}
		}
		else
		{
			iterator = backUpIterator;
			return false;
		}
	}
	else
	{
		symbol = *iterator++;
		return false;
	}
	return false;
}

inline void SimpleTextImplDetails::Label(const char* text, int posX, int posY, SimpleText::Alignment a)
{
	const char* begin = text;
	const char* end = begin;
	for (; *end != '\0';++end);

	int offset = m_vertex_buffer_offset;

	int pos = 0;
	int symbol_size = SYMBOL_WIDTH * m_fontsize;
	for (const char* it = begin; it != end;)
	{
		char symbol = '\0';
		if (!m_ansiDecoder.DecodeEscapeCode(it, end, symbol))
		{
			SubmitSymbol(symbol, static_cast<float>(posX), static_cast<float>(posY), pos);
			++pos;
		}
	}
	switch(a)
	{
		case SimpleText::LEFT: return;
		case SimpleText::CENTER: pos /= 2; break;
		case SimpleText::RIGHT: break;
	}

	uint8_t* ptr = m_vertex_buffer + offset * vertex_size;
	for (int i = offset; i < m_vertex_buffer_offset; ++i)
	{
		*(int16_t*)(ptr + 0) -= 4 * symbol_size * pos;
		ptr += vertex_size;
	}
}

inline void SimpleTextImplDetails::EnableBlending(bool enable)
{
	m_blendingEnabled = enable;
}

inline void SimpleTextImplDetails::SetColor(SimpleText::ForegroundBackground type, SimpleText::Color color, SimpleText::NormalBold bold)
{
	unsigned char r, g, b;
	DecodeColor(color, bold, r, g, b);
	uint8_t* previousColor = nullptr;
	SimpleText::Color* effectedColor = nullptr;
	switch (type)
	{
	case SimpleText::TEXT_COLOR:
		previousColor = m_textColor;
		effectedColor = &m_ansiTextColor;
		break;
	case SimpleText::BACKGROUND_COLOR:
		previousColor = m_backColor;
		effectedColor = &m_ansiBackgroundColor;
		break;
	}
	if (previousColor != nullptr)
	{
		SetColor(type, r, g, b, 255);
	}
	if (effectedColor != nullptr)
	{
		*effectedColor = color;
		m_ansiBold = bold;
	}
}

inline void SimpleTextImplDetails::GetColor(SimpleText::ForegroundBackground type, SimpleText::Color& color, SimpleText::NormalBold& bold)
{
	switch (type)
	{
	case SimpleText::TEXT_COLOR:
		color = m_ansiTextColor;
		break;
	case SimpleText::BACKGROUND_COLOR:
		color = m_ansiBackgroundColor;
		break;
	}	
	bold = m_ansiBold;
}

inline void SimpleTextImplDetails::ResetAnsiColor()
{
	m_ansiTextColor = SimpleText::WHITE;
	m_ansiBackgroundColor = SimpleText::BLACK;
	m_ansiBold = SimpleText::NORMAL;
}

inline void SimpleTextImplDetails::SetColor(SimpleText::ForegroundBackground type, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
	uint8_t *color = NULL;
	switch (type)
	{
	case SimpleText::TEXT_COLOR:
		color = m_textColor;
		break;
	case SimpleText::BACKGROUND_COLOR:
		color = m_backColor;
		break;
	}
	if (color != NULL)
	{
		color[0] = r;
		color[1] = g;
		color[2] = b;
		color[3] = a;
	}
	ResetAnsiColor();
}

inline void SimpleTextImplDetails::DecodeColor(SimpleText::Color color, SimpleText::NormalBold bold, unsigned char& r, unsigned char& g, unsigned char& b)
{
	typedef struct{
		unsigned char data [3];
	} Color;
	Color colorsNormal[SimpleText::COLOR_COUNT] = {
		{ { 0x00, 0x00, 0x00 } },
		{ { 0xaa, 0x00, 0x00 } },
		{ { 0x00, 0xaa, 0x00 } },
		{ { 0xaa, 0x55, 0x00 } },
		{ { 0x00, 0x00, 0xaa } },
		{ { 0xaa, 0x00, 0xaa } },
		{ { 0x00, 0xaa, 0xaa } },
		{ { 0xaa, 0xaa, 0xaa } },
	};
	Color colorsBright[SimpleText::COLOR_COUNT] = {
		{ { 0x55, 0x55, 0x55 } },
		{ { 0xff, 0x55, 0x55 } },
		{ { 0x55, 0xff, 0x55 } },
		{ { 0xff, 0xff, 0x55 } },
		{ { 0x55, 0x55, 0xff } },
		{ { 0xff, 0x55, 0xff } },
		{ { 0x55, 0xff, 0xff } },
		{ { 0xff, 0xff, 0xff } },
	};
	Color* colors = bold == SimpleText::NORMAL ? colorsNormal : colorsBright;
	r = colors[color].data[0];
	g = colors[color].data[1];
	b = colors[color].data[2];
}

inline void SimpleTextImplDetails::SetTextSize(SimpleText::FontSize size)
{
	m_fontsize = size;
	m_sizeX = SYMBOL_WIDTH * m_fontsize;
	m_sizeY = SYMBOL_HEIGHT * m_fontsize;
}

inline bool SimpleTextImplDetails::Succeeded(GLuint object, Stage stage)
{
	GLint maxLength = 0;
	GLint status = GL_FALSE;
	char* infoLog = nullptr;
	switch (stage)
	{
	case COMPILE:
		glGetShaderiv(object, GL_COMPILE_STATUS, &status);
		glGetShaderiv(object, GL_INFO_LOG_LENGTH, &maxLength);
		if (maxLength > 1)
		{
			infoLog = new char[static_cast<GLuint>(maxLength)];
			glGetShaderInfoLog(object, maxLength, &maxLength, infoLog);
		}
		break;
	case LINK:
		glGetProgramiv(object, GL_LINK_STATUS, &status);
		glGetProgramiv(object, GL_INFO_LOG_LENGTH, &maxLength);
		if (maxLength > 1)
		{
			infoLog = new char[static_cast<GLuint>(maxLength)];
			glGetProgramInfoLog(object, maxLength, &maxLength, infoLog);
		}
		break;
	}
	bool return_value = true;
	if (maxLength > 1)
	{
		if (status == GL_FALSE)
		{
			return_value = false;
			SIMPLE_TEXT_PRINT_ERROR("GLSL Error\n");
		}
		else
		{
			SIMPLE_TEXT_PRINT_ERROR("GLSL Warning\n");
		}
		SIMPLE_TEXT_PRINT_ERROR("%s\n", infoLog);
	}
	else if (status == GL_FALSE)
	{
		return_value = false;
		SIMPLE_TEXT_PRINT_ERROR("Error without info log\n");
	}
	delete[] infoLog;
	return return_value;
}

inline void SimpleTextImplDetails::ResizeVertexBuffer(size_t newSize)
{
	assert(newSize % 4 == 0);
	if (newSize > m_vertex_buffer_reserved)
	{
		uint64_t v = newSize + 1;

		v--;
		v |= v >> 1U;
		v |= v >> 2U;
		v |= v >> 4U;
		v |= v >> 8U;
		v |= v >> 16U;
		v |= v >> 32U;
		v++;

		uint64_t old_reserved = m_vertex_buffer_reserved;
		m_vertex_buffer_reserved = static_cast<size_t>(v);
		m_vertex_buffer = static_cast<uint8_t*>(realloc(m_vertex_buffer, vertex_size * m_vertex_buffer_reserved));
		m_index_buffer = static_cast<uint16_t*>(realloc(m_index_buffer, sizeof(uint16_t) * m_vertex_buffer_reserved / 4 * 6));

		uint64_t start_index =old_reserved / 4 * 6;
		for (int i = old_reserved; i < m_vertex_buffer_reserved; i += 4)
		{
			m_index_buffer[start_index + 0] = i + 0;
			m_index_buffer[start_index + 1] = i + 1;
			m_index_buffer[start_index + 2] = i + 2;
			m_index_buffer[start_index + 3] = i + 0;
			m_index_buffer[start_index + 4] = i + 2;
			m_index_buffer[start_index + 5] = i + 3;
			start_index += 6;
		}
	}
	m_vertex_buffer_size = newSize;
}

inline void SimpleTextImplDetails::SubmitSymbol(char _symbol, float posX, float posY, int shift)
{
	m_sizeX = SYMBOL_WIDTH * m_fontsize;
	m_sizeY = SYMBOL_HEIGHT * m_fontsize;
	int symbol = (unsigned char)_symbol;
	int y = symbol / (TEXTURE_SIZE_X / 2 / SYMBOL_WIDTH);
	int x = symbol % (TEXTURE_SIZE_X / 2 / SYMBOL_WIDTH);
	x *= 2;

	int16_t uv[4] = {
			static_cast<int16_t>(4 * SYMBOL_WIDTH * x),
			static_cast<int16_t>(4 * SYMBOL_HEIGHT * y),
			static_cast<int16_t>(4 * SYMBOL_WIDTH * (x + 1)),
			static_cast<int16_t>(4 * SYMBOL_HEIGHT * (y + 1))
	};

	int16_t pos[4] = {
			static_cast<int16_t>(4 * (shift * m_sizeX + posX)),
			static_cast<int16_t>(4 * (posY - m_sizeY)),
			static_cast<int16_t>(4 * (shift * m_sizeX + posX + m_sizeX)),
			static_cast<int16_t>(4 * (posY))
	};

	int ids[] = {0, 1, 0, 3, 2, 3, 2, 1};

	ResizeVertexBuffer(4 + m_vertex_buffer_offset);

	uint8_t* ptr = m_vertex_buffer + m_vertex_buffer_offset * vertex_size;

	for (int i = 0; i < 4; ++i)
	{
		memcpy(ptr, pos + ids[2 * i + 0], sizeof(int16_t)); ptr += sizeof(int16_t);
		memcpy(ptr, pos + ids[2 * i + 1], sizeof(int16_t)); ptr += sizeof(int16_t);
		memcpy(ptr, uv + ids[2 * i + 0], sizeof(int16_t)); ptr += sizeof(int16_t);
		memcpy(ptr, uv + ids[2 * i + 1], sizeof(int16_t)); ptr += sizeof(int16_t);
		memcpy(ptr, m_textColor, sizeof(uint8_t) * 4); ptr += 4 * sizeof(uint8_t);
		memcpy(ptr, m_backColor, sizeof(uint8_t) * 4); ptr += 4 * sizeof(uint8_t);
	}
	m_vertex_buffer_offset += 4;
	m_vertex_count += 4;
}

inline void SimpleTextImplDetails::Render()
{
	glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
	glBufferData(GL_ARRAY_BUFFER, m_vertex_count * vertex_size, m_vertex_buffer, GL_STREAM_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_vertex_count / 4 * 6 * sizeof(short), m_index_buffer, GL_STREAM_DRAW);
	StartDraw();

	glDrawElements(GL_TRIANGLES, m_vertex_count / 4 * 6, GL_UNSIGNED_SHORT, 0);

	EndDraw();
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	m_vertex_buffer_offset = 0;
	m_vertex_count = 0;
}

inline void SimpleTextImplDetails::CreateVBO()
{
	glGenBuffers(1, &m_vbo);
	glGenBuffers(1, &m_ibo);
}

inline void SimpleTextImplDetails::Free()
{
	glDeleteBuffers(1, &m_vbo);
	glDeleteBuffers(1, &m_ibo);
	glDeleteProgram(m_shaderprogram);
	glDeleteShader(m_vertexShader);
	glDeleteShader(m_fragmentShader);
	glDeleteTextures(1, &m_texture);
	free(m_vertex_buffer);
	free(m_index_buffer);
}

inline void SimpleTextImplDetails::StartDraw()
{
	glUseProgram(m_shaderprogram);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_texture);

	int i = 0;
	glUniform1iv(u_texture, 1, &i);

	glGetIntegerv(GL_VIEWPORT, m_viewport);
	glUniform2i(u_viewport, m_viewport[2], m_viewport[3]);

	m_backUpBlendingState = glIsEnabled(GL_BLEND);
	if (m_blendingEnabled)
	{
		if (!m_backUpBlendingState)
		{
			glEnable(GL_BLEND);
		}

		glGetIntegerv(GL_BLEND_SRC_RGB, &m_backUpSfactorRGB);
		glGetIntegerv(GL_BLEND_DST_RGB, &m_backUpDfactorRGB);
		glGetIntegerv(GL_BLEND_SRC_ALPHA, &m_backUpSfactorAlpha);
		glGetIntegerv(GL_BLEND_DST_ALPHA, &m_backUpDfactorAlpha);

		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	else
	{
		if (m_backUpBlendingState)
		{
			glDisable(GL_BLEND);
		}
	}

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);

	glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
	glEnableVertexAttribArray(AttributePosition);
	glVertexAttribPointer(AttributePosition, 2, GL_SHORT, GL_FALSE, vertex_size, 0);
	glEnableVertexAttribArray(AttributeTextureCoord);
	glVertexAttribPointer(AttributeTextureCoord, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertex_size, (GLvoid*)(2 * sizeof(int16_t)));
	glEnableVertexAttribArray(AttributeColorF);
	glVertexAttribPointer(AttributeColorF, 4, GL_UNSIGNED_BYTE, GL_FALSE, vertex_size, (GLvoid*)(4 * sizeof(uint16_t)));
	glEnableVertexAttribArray(AttributeColorB);
	glVertexAttribPointer(AttributeColorB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vertex_size, (GLvoid*)(4 * sizeof(uint16_t)+ 4 * sizeof(uint8_t)));
}

inline void SimpleTextImplDetails::EndDraw()
{
	if (m_blendingEnabled)
	{
		if (!m_backUpBlendingState)
		{
			glDisable(GL_BLEND);
		}
		glBlendFuncSeparate(static_cast<GLenum>(m_backUpSfactorRGB), static_cast<GLenum>(m_backUpDfactorRGB), static_cast<GLenum>(m_backUpSfactorAlpha), static_cast<GLenum>(m_backUpDfactorAlpha));
	}
	glDisableVertexAttribArray(AttributePosition);
	glDisableVertexAttribArray(AttributeTextureCoord);
	glDisableVertexAttribArray(AttributeColorF);
	glDisableVertexAttribArray(AttributeColorB);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}

inline void SimpleTextImplDetails::CreateShaderProgram()
{
	const GLchar* vShaderCode =
		"#ifdef GL_ES \n"
        "precision mediump float; \n"
		"#endif \n"
		"attribute vec2 in_position; \n"
		"attribute vec2 in_coord; \n"
		"attribute vec4 in_colorf; \n"
		"attribute vec4 in_colorb; \n"
		"uniform ivec2 u_viewport; \n"
		"varying vec2 out_coord; \n"
		"varying vec4 out_colorf; \n"
		"varying vec4 out_colorb; \n"
		"void main() {\n"
        "   vec2 pos = 2.0 * in_position / vec2(u_viewport * 4) - vec2(1.0);"
		"	gl_Position = vec4(pos.x, -pos.y, 0.0, 1.0); \n"
		"	out_coord = in_coord / vec2(256.0, 256.0) / 4.0; \n"
		"	out_colorf = in_colorf / 255.0; \n"
		"	out_colorb = in_colorb / 255.0; \n"
		"}\n";

	const GLchar* fShaderCode =
		"#ifdef GL_ES \n"
		"precision mediump float; \n"
		"#endif \n"
		"varying vec2 out_coord; \n"
		"varying vec4 out_colorf; \n"
		"varying vec4 out_colorb; \n"
		"uniform sampler2D text; \n"
		"void main() {\n"
		"	float c = float(texture2D(text, out_coord).r > 0.4); \n"
		"	gl_FragColor = mix(out_colorb, out_colorf, vec4(c)); \n"
		"}\n";
	
	m_vertexShader = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource(m_vertexShader, 1, &vShaderCode, 0);
	glCompileShader(m_vertexShader);

	if (!Succeeded(m_vertexShader, COMPILE))
	{
		return;
	}

	m_fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(m_fragmentShader, 1, &fShaderCode, 0);
	glCompileShader(m_fragmentShader);

	if (!Succeeded(m_fragmentShader, COMPILE))
	{
		return;
	}

	m_shaderprogram = glCreateProgram();
	glAttachShader(m_shaderprogram, m_vertexShader);
	glAttachShader(m_shaderprogram, m_fragmentShader);
	glLinkProgram(m_shaderprogram);

	if (!Succeeded(m_shaderprogram, LINK))
	{
		return;
	}
}

inline void SimpleTextImplDetails::BindUniforms()
{
	u_texture = glGetUniformLocation(m_shaderprogram, "text");
	u_viewport = glGetUniformLocation(m_shaderprogram, "u_viewport");
}

inline void SimpleTextImplDetails::BindAttributes()
{
	glBindAttribLocation(m_shaderprogram, AttributePosition, "in_position");
	glBindAttribLocation(m_shaderprogram, AttributeTextureCoord, "in_coord");
	glBindAttribLocation(m_shaderprogram, AttributeColorF, "in_colorf");
	glBindAttribLocation(m_shaderprogram, AttributeColorB, "in_colorb");
}

inline void SimpleTextImplDetails::CreateFontTexture()
{
	GLuint texture[1];
	glGenTextures(1, &texture[0]);
	m_texture = texture[0];

	glBindTexture(GL_TEXTURE_2D, m_texture);

	unsigned char* buff = GenerateFontBitmap();

#if defined __EMSCRIPTEN__ || TARGET_OS_IPHONE
	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, TEXTURE_SIZE_X, TEXTURE_SIZE_Y, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, buff);
#else
	glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, TEXTURE_SIZE_X, TEXTURE_SIZE_Y, 0, GL_RED, GL_UNSIGNED_BYTE, buff);
#endif
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glBindTexture(GL_TEXTURE_2D, 0);

	delete[] buff;
}

inline unsigned char* SimpleTextImplDetails::GenerateFontBitmap()
{
	unsigned char vgaFont[SYMBOL_COUNT * SYMBOL_HEIGHT] = {
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xa5, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xdb, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x36, 0x7f, 0x7f, 0x7f, 0x7f, 0x3e, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x3e, 0x7f, 0x3e, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
		0x00, 0x00, 0x78, 0x60, 0x70, 0x58, 0x1e, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0xfc, 0xcc, 0xfc, 0x0c, 0x0c, 0x0c, 0x0c, 0x0e, 0x0f, 0x07, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0xfe, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xe6, 0xe7, 0x67, 0x03, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7f, 0x7c, 0x78, 0x70, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0xfe, 0xdb, 0xdb, 0xdb, 0xde, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x3e, 0x63, 0x06, 0x1c, 0x36, 0x63, 0x63, 0x36, 0x1c, 0x30, 0x63, 0x3e, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x7f, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x06, 0x7f, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x36, 0x7f, 0x36, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x1c, 0x3e, 0x3e, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x3e, 0x3e, 0x1c, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x36, 0x36, 0x7f, 0x36, 0x36, 0x36, 0x7f, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00,
		0x18, 0x18, 0x3e, 0x63, 0x43, 0x03, 0x3e, 0x60, 0x60, 0x61, 0x63, 0x3e, 0x18, 0x18, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x43, 0x63, 0x30, 0x18, 0x0c, 0x06, 0x63, 0x61, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x1c, 0x36, 0x36, 0x1c, 0x6e, 0x3b, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x0c, 0x0c, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x1c, 0x36, 0x63, 0x63, 0x6b, 0x6b, 0x63, 0x63, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x1c, 0x1e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3e, 0x63, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3e, 0x63, 0x60, 0x60, 0x3c, 0x60, 0x60, 0x60, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x30, 0x38, 0x3c, 0x36, 0x33, 0x7f, 0x30, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7f, 0x03, 0x03, 0x03, 0x3f, 0x60, 0x60, 0x60, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x1c, 0x06, 0x03, 0x03, 0x3f, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7f, 0x63, 0x60, 0x60, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x7e, 0x60, 0x60, 0x60, 0x30, 0x1e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3e, 0x63, 0x63, 0x30, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x7b, 0x7b, 0x7b, 0x3b, 0x03, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x3f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3c, 0x66, 0x43, 0x03, 0x03, 0x03, 0x03, 0x43, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x1f, 0x36, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x36, 0x1f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7f, 0x66, 0x46, 0x16, 0x1e, 0x16, 0x06, 0x46, 0x66, 0x7f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7f, 0x66, 0x46, 0x16, 0x1e, 0x16, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3c, 0x66, 0x43, 0x03, 0x03, 0x7b, 0x63, 0x63, 0x66, 0x5c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x67, 0x66, 0x66, 0x36, 0x1e, 0x1e, 0x36, 0x66, 0x66, 0x67, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x0f, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x77, 0x7f, 0x7f, 0x6b, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x67, 0x6f, 0x7f, 0x7b, 0x73, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x6b, 0x7b, 0x3e, 0x30, 0x70, 0x00, 0x00,
		0x00, 0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x36, 0x66, 0x66, 0x66, 0x67, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3e, 0x63, 0x63, 0x06, 0x1c, 0x30, 0x60, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7e, 0x7e, 0x5a, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x36, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x6b, 0x6b, 0x6b, 0x7f, 0x77, 0x36, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x63, 0x36, 0x3e, 0x1c, 0x1c, 0x3e, 0x36, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7f, 0x63, 0x61, 0x30, 0x18, 0x0c, 0x06, 0x43, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x08, 0x1c, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
		0x0c, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x07, 0x06, 0x06, 0x1e, 0x36, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x03, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x38, 0x30, 0x30, 0x3c, 0x36, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x7f, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x1c, 0x36, 0x26, 0x06, 0x0f, 0x06, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3e, 0x30, 0x33, 0x1e, 0x00,
		0x00, 0x00, 0x07, 0x06, 0x06, 0x36, 0x6e, 0x66, 0x66, 0x66, 0x66, 0x67, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x18, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x60, 0x60, 0x00, 0x70, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x66, 0x66, 0x3c, 0x00,
		0x00, 0x00, 0x07, 0x06, 0x06, 0x66, 0x36, 0x1e, 0x1e, 0x36, 0x66, 0x67, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x7f, 0x6b, 0x6b, 0x6b, 0x6b, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x0f, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3e, 0x30, 0x30, 0x78, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x6e, 0x66, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x06, 0x1c, 0x30, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x08, 0x0c, 0x0c, 0x3f, 0x0c, 0x0c, 0x0c, 0x0c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x6b, 0x6b, 0x6b, 0x7f, 0x36, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x36, 0x1c, 0x1c, 0x1c, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x7e, 0x60, 0x30, 0x1f, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x33, 0x18, 0x0c, 0x06, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x0e, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x6e, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x63, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x3c, 0x66, 0x43, 0x03, 0x03, 0x03, 0x43, 0x66, 0x3c, 0x30, 0x60, 0x3e, 0x00, 0x00,
		0x00, 0x00, 0x33, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x30, 0x18, 0x0c, 0x00, 0x3e, 0x63, 0x7f, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x08, 0x1c, 0x36, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x33, 0x00, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x06, 0x0c, 0x18, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x1c, 0x36, 0x1c, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x06, 0x06, 0x66, 0x3c, 0x30, 0x60, 0x3c, 0x00, 0x00, 0x00,
		0x00, 0x08, 0x1c, 0x36, 0x00, 0x3e, 0x63, 0x7f, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x00, 0x00, 0x3e, 0x63, 0x7f, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x06, 0x0c, 0x18, 0x00, 0x3e, 0x63, 0x7f, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x66, 0x00, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x18, 0x3c, 0x66, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x06, 0x0c, 0x18, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x63, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x1c, 0x36, 0x1c, 0x00, 0x1c, 0x36, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x18, 0x0c, 0x06, 0x00, 0x7f, 0x66, 0x06, 0x3e, 0x06, 0x06, 0x66, 0x7f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x6e, 0x6c, 0x7e, 0x1b, 0x1b, 0x76, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7c, 0x36, 0x33, 0x33, 0x7f, 0x33, 0x33, 0x33, 0x33, 0x73, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x08, 0x1c, 0x36, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x06, 0x0c, 0x18, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x0c, 0x1e, 0x33, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x06, 0x0c, 0x18, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x7e, 0x60, 0x30, 0x1e, 0x00,
		0x00, 0x63, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x63, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x18, 0x18, 0x3c, 0x66, 0x06, 0x06, 0x06, 0x66, 0x3c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x1c, 0x36, 0x26, 0x06, 0x0f, 0x06, 0x06, 0x06, 0x06, 0x67, 0x3f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x1f, 0x33, 0x33, 0x1f, 0x23, 0x33, 0x7b, 0x33, 0x33, 0x33, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x70, 0xd8, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1b, 0x0e, 0x00, 0x00,
		0x00, 0x18, 0x0c, 0x06, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x30, 0x18, 0x0c, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x18, 0x0c, 0x06, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x18, 0x0c, 0x06, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x6e, 0x3b, 0x00, 0x3b, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00,
		0x6e, 0x3b, 0x00, 0x63, 0x67, 0x6f, 0x7f, 0x7b, 0x73, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x3c, 0x36, 0x36, 0x7c, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x1c, 0x36, 0x36, 0x1c, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x06, 0x03, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x03, 0x03, 0x43, 0x63, 0x33, 0x18, 0x0c, 0x06, 0x3b, 0x61, 0x30, 0x18, 0x7c, 0x00, 0x00,
		0x00, 0x03, 0x03, 0x43, 0x63, 0x33, 0x18, 0x0c, 0x66, 0x73, 0x79, 0x7c, 0x60, 0x60, 0x00, 0x00,
		0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x36, 0x1b, 0x36, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x36, 0x6c, 0x36, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22,
		0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55,
		0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6f, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6f, 0x60, 0x6f, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x60, 0x6f, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6f, 0x60, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xec, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xec, 0x0c, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0xec, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xef, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xef, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xec, 0x0c, 0xec, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xef, 0x00, 0xef, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xff, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c,
		0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
		0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
		0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x3b, 0x1b, 0x1b, 0x1b, 0x3b, 0x6e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x1e, 0x33, 0x33, 0x33, 0x1b, 0x33, 0x63, 0x63, 0x63, 0x33, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x7f, 0x63, 0x63, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x7f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x7f, 0x63, 0x06, 0x0c, 0x18, 0x0c, 0x06, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x03, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x6e, 0x3b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x7e, 0x18, 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x1c, 0x36, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x1c, 0x36, 0x63, 0x63, 0x63, 0x36, 0x36, 0x36, 0x36, 0x77, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x78, 0x0c, 0x18, 0x30, 0x7c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0xc0, 0x60, 0x7e, 0xdb, 0xdb, 0xcf, 0x7e, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x38, 0x0c, 0x06, 0x06, 0x3e, 0x06, 0x06, 0x06, 0x0c, 0x38, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x70, 0xd8, 0xd8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
		0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1b, 0x1b, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x3b, 0x00, 0x6e, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x1c, 0x36, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0xf0, 0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x36, 0x36, 0x3c, 0x38, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x1b, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x0e, 0x1b, 0x0c, 0x06, 0x13, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	};

	unsigned char* buff = new unsigned char[TEXTURE_SIZE_Y * TEXTURE_SIZE_X];
	for (unsigned int i = 0; i < TEXTURE_SIZE_Y; i++)
	{
		for (unsigned int j = 0; j < TEXTURE_SIZE_X; j++)
		{
			unsigned int x = j >> 3U;
			if (x % 2 == 1)
				continue;
			unsigned int y = i >> 4U;
			unsigned char v = 0;
			unsigned int pos = y * TEXTURE_SIZE_X / 2 / SYMBOL_WIDTH + x / 2;
			unsigned int py = i & 0b00001111U;
			unsigned int px = j & 0b00000111U;

			unsigned char m = vgaFont[pos * SYMBOL_HEIGHT + py] & (1U << px);
			v = static_cast<unsigned char>((m == 0 ? 0x00 : 0xff));

			buff[i * TEXTURE_SIZE_X + j] = v;
		}
	}
	return buff;
}
